package com.goods.controller.business;

import com.goods.business.service.InStockService;
import com.goods.common.model.business.Supplier;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.InStockDetailVO;
import com.goods.common.vo.business.InStockVO;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Api(tags = "业务模块-入库相关接口")
@RestController
@RequestMapping("/business/inStock")
public class InStockController {

    @Autowired
    private InStockService inStockService;

    @ApiOperation(value = "物资资料分页列表展示 && 条件查询")
    @GetMapping("/findInStockList")
    public ResponseBean findInStockList(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize,
            InStockVO inStockVO
    ){
        PageVO<InStockVO> inStockVOPageVO =
                inStockService.findInStockList(pageNum,pageSize,inStockVO);
        return ResponseBean.success(inStockVOPageVO);
    }

    @ApiOperation(value = "物资入库明细")
    @GetMapping("/detail/{id}")
    public ResponseBean detail(@PathVariable Long id,
                               @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum){

        InStockDetailVO inStockDetailVO = inStockService.detail(id);
        return ResponseBean.success(inStockDetailVO);
    }

    @ApiOperation(value = "移入回收站")
    @PutMapping("/remove/{id}")
    public ResponseBean remove(@PathVariable Long id){
        inStockService.remove(id);
        return ResponseBean.success();
    }

    @ApiOperation(value = "恢复入库")
    @PutMapping("/back/{id}")
    public ResponseBean back(@PathVariable Long id){
        inStockService.back(id);
        return ResponseBean.success();
    }

    @ApiOperation(value = "删除入库")
    @DeleteMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id){
        inStockService.delete(id);
        return ResponseBean.success();
    }

    @ApiOperation(value = "添加入库单")
    @PostMapping("/addIntoStock")
    public ResponseBean addIntoStock(@RequestBody InStockVO inStockVO,
                                     @RequestBody Supplier supplier){

        inStockService.addIntoStock(inStockVO,supplier);
        return ResponseBean.success();
    }

}
